﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="lisadokument_type", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(LisadokumentType))]
    public class LisadokumentTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ILisadokumentType clazz;
        
        public LisadokumentTypeSerializer(ILisadokumentType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("id");
            if (clazz.Id!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Id))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Id");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("e_dokument_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.EDokumentId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("failinimi");
            if (clazz.Failinimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Failinimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Failinimi");
            }
            Writer.WriteEndElement();
            if (clazz.DigidocViit!=null) {
                Writer.WriteStartElement("digidoc_viit");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DigidocViit))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("liik");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Liik))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>lisadokument_type>id");
                }
                clazz.Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>lisadokument_type>id", Reader.LocalName);
            }
            if (Reader.LocalName=="e_dokument_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>lisadokument_type>e_dokument_id");
                }
                clazz.EDokumentId = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("e_dokument_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>lisadokument_type>e_dokument_id", Reader.LocalName);
            }
            if (Reader.LocalName=="failinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>lisadokument_type>failinimi");
                }
                clazz.Failinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("failinimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>lisadokument_type>failinimi", Reader.LocalName);
            }
            if (Reader.LocalName=="digidoc_viit") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>lisadokument_type>digidoc_viit");
                }
                clazz.DigidocViit = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("digidoc_viit")).Value;
            }
            if (Reader.LocalName=="liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>lisadokument_type>liik");
                }
                clazz.Liik = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("liik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>lisadokument_type>liik", Reader.LocalName);
            }
        }
    }
}
